<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>


<body>
  <div id="test"></div>
</body>



<script type="text/javascript" src="../js/react.development.js"></script>
<script type="text/javascript" src="../js/react-dom.development.js"></script>
<script type="text/javascript" src="../js/babel.min.js"></script>
<script type="text/javascript" src="../js/prop-types.js"></script>

<script type="text/babel"> //必须声明 babel
  class Count extends React.Component {
    constructor(props) {
      super(props)
      console.log('Count-constructor');
    }
    state = {
      count: 1
    }
    //组件将要挂载
    componentWillMount () {
      console.log('Count-组件将要挂载');

    }
    //组价挂载完毕
    componentDidMount () {
      console.log('Count-组件挂载完毕');

    }
    //控制组件更新的阀门  return true/false   false阻断
    shouldComponentUpdate = () => {
      console.log('Count-控制组件更新的阀门 ');
      return true
    }
    //组件将要更新的钩子
    componentWillUpdate () {
      console.log('Count-组件将要更新的钩子');
    }
    //组件更新完毕的钩子
    componentDidUpdate () {
      console.log('Count-组件更新完毕的钩子');
    }
    //组件将要卸载
    componentWillUnmount () {
      console.log('Count-组件将要卸载');
    }

    addHandle = () => {
      const { count } = this.state
      this.setState({
        count: count + 1
      })
    }
    clearDeath = () => {
      ReactDOM.unmountComponentAtNode(document.getElementById('test'))
    }

    render () {
      console.log('Count-render组件');

      const { count } = this.state
      return (
        <div>
          <h2>{count}</h2>
          <button onClick={this.addHandle}>点击++</button>
          <button onClick={this.clearDeath}>卸载组件</button>

        </div>

      )
    }
  }
  ReactDOM.render(<Count />, document.getElementById('test'))
</script>

</html>